#ifndef _ALI_PLAY_H_
#define _ALI_PLAY_H_

typedef void *HALIPLAY;

#define STR_LEN 32
typedef struct {
	char id[STR_LEN];
	char alias[STR_LEN];
	char model[STR_LEN];
	char version[STR_LEN];
} DEVICE_INFO;

typedef struct {
	unsigned short discover_port;
	unsigned short http_port;
} SERVICE_INFO;

typedef struct {
	int year;
	int month;
	int day;
	int weekday;
} EPG_EVENT_DATE;

typedef struct {
	int hour;
	int minute;
	int second;
} EPG_EVENT_TIME;

typedef struct {
	EPG_EVENT_DATE date;
	EPG_EVENT_TIME time;
} EPG_EVENT_DATETIME;

#define MAX_SERVICE_NAME_LEN_MINUS_ONE	35
#define MAX_EVENT_NAME_LEN_MINUS_ONE	31
#define MAX_DESC_UNIT_LEN		256
#define MAX_EVENT_BRIEF_LEN_MINUS_ONE	(MAX_DESC_UNIT_LEN - 1)
#define MAX_EVENT_DETAIL_LEN_MINUS_ONE	((MAX_DESC_UNIT_LEN * 16) - 1)

typedef struct {
	char name[MAX_SERVICE_NAME_LEN_MINUS_ONE + 1];
	EPG_EVENT_DATE date;
	int channel;
} EPG_SERVICE;

typedef struct {
	EPG_EVENT_TIME start_time;
	EPG_EVENT_TIME end_time;
} EPG_EVENT_DURATION;

typedef struct {
	char name[MAX_EVENT_NAME_LEN_MINUS_ONE + 1];
	EPG_EVENT_DURATION duration;
} EPG_EVENT_PREVIEW;

typedef struct {
	EPG_EVENT_PREVIEW preview;
	char brief[MAX_EVENT_BRIEF_LEN_MINUS_ONE + 1];
	char detail[MAX_EVENT_DETAIL_LEN_MINUS_ONE + 1];
} EPG_EVENT;

// NOTE: 对于所有返回值为整型的回调函数实现: 成功返回 0, 否则返回 -1.
typedef struct {
	// 获取设备静态信息
	void (*device_info)(void *userdata, DEVICE_INFO *info);
	void (*service_info)(void *userdata, SERVICE_INFO *info);

	//void (*pairing_complete)(void *userdata);
	
	// 动态信息通过单独的接口获取
	int (*epg_service_name)(void *userdata, char *lang_code, int channel, EPG_SERVICE *service);
	/**
	 * channel: -1: 表示当前通道
	 * lang_code: 语言代码(ISO639-2), 如 eng 表示英文，chi 表示中文
	 * weekday: 0 ~ 6, 0 代表今天，1代表明天，以此类推
	 * start: 表示从哪个事件开始读起
	 * num: 请求EVENT的数量，输入时指明有效的输出空间，输出时指明 schedule 当中有效数据的数量.
	 * schedule: EPG_EVENT_PREVIEW 结构体数组
	 */
	int (*epg_schedule)(void *userdata, char *lang_code, int channel, int weekday, int start, int *num, EPG_EVENT_PREVIEW *schedule);
	/**
	 * index: 表示请求读取哪个事件
	 * event: 输出结构体
	 */
	int (*epg_event)(void *userdata, char *lang_code, int channel, int weekday, int index, EPG_EVENT *event);
	
	int (*record_remind)(void *userdata, int weekday, int index, int is_record);
	
	// 20130705/Billy/支持普通频道号和 PROGRAM ID 这两种换台方式
	//int (*change_channel_to)(void *userdata, int channel);
	int (*change_channel_to)(void *userdata, int channel, int is_channel_id);

	int (*input_content)(void *userdate, char *content);
	int (*move_cursor)(void *userdata, int x, int y);
	int (*simple_command)(void *userdate, char *cmd);
	int (*key_command)(void *userdate, int key);

	int (*file_size)(void *userdata, char *name, int *size);
	int (*file_data)(void *userdata, char *name, long offset, int size, char *buf);
} ALIPLAY_OPERATIONS;

/* 打开 ALiPlay 服务.
 *
 * 成功则返回有效的 ALiPlay 服务句柄, 否则返回 NULL.
 */
HALIPLAY aliplay_open(ALIPLAY_OPERATIONS *ops, void *userdata);

/* 启动 ALiPlay 服务.
 *
 * 成功返回 0, 否则返回 -1.
 */
int aliplay_start(HALIPLAY handle);

/* 停止 ALiPlay 服务.
 *
 * 成功返回 0, 否则返回 -1.
 */
int aliplay_stop(HALIPLAY handle);

/* 关闭 ALiPlay 服务.
 *
 */
void aliplay_close(HALIPLAY handle);

/* 进入配对模式. STB 在打开配对窗口前调用此接口, 以使 ALiPlay 模式进入配对模式并获取随机生成的 pairing_code.
 * pairing_code 用于显示在配对窗口上, 其长度为 5 个字节.
 * 
 * 成功返回 0, 否则返回 -1.
 */
int aliplay_enable_pairing(HALIPLAY handle, char *pairing_code);

/* 退出配对模式. STB 在关闭配对窗口前调用此接口. 
 *
 * 成功返回 0, 否则返回 -1.
 */
int aliplay_disable_pairing(HALIPLAY handle);

#endif//_ALI_PLAY_H_
